package com.summarecon.database;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class DatabaseBlueprint {
	private static final String TABLE_HOME_TYPE = "tipe_rumah";
	
	private SQLiteDatabase db;  
	private Context context = null;  
	private DatabaseHelper DBHelper;

	public DatabaseBlueprint(Context ctx) 
	{
		this.context = ctx;
		DBHelper = new DatabaseHelper(context);
	}

	public void open() throws SQLException 
	{
		db = DBHelper.getWritableDatabase();
	}


	public void close() 
	{
		DBHelper.close();
	}

	public byte[] getImageData()
	{
		
		byte[] dataGambar = null;
		
		Cursor cursor;

		try
		{
			
			cursor = db.rawQuery("SELECT * FROM " + TABLE_HOME_TYPE + " WHERE tipe_id=?", new String[]{"1"});
			
			if (cursor != null) {           
				if(cursor.getCount() > 0)
				{
					if  (cursor.moveToFirst()) {
						do {
							dataGambar = (cursor.getBlob(cursor.getColumnIndex("tipe_tampak_atas")));
						}while (cursor.moveToNext());
					}
				}
			}
		}
		catch (SQLException e)
		{
			Log.e("DB Error", e.toString());
			e.printStackTrace();
		}

		return dataGambar;
	}
}
